<template>
	<div v-loading="!isShow">
		<div class="zs-card-sm zs-space-bottom zs-layout-flex-row">
			<el-select v-model="biProjectCode" class="zs-select-md zs-space-right-sm" placeholder="项目名称" @change="changeProject()">
				<el-option v-for="item in projectList" :key="item.biProjectCode" :label="item.projectName" :value="item.biProjectCode" />
			</el-select>
			<el-date-picker v-if="isShowDigitalMonthlyReport" class="zs-select-md zs-space-right-sm" v-model="yearmonth" type="month" placeholder="月份" value-format="YYYY-MM" :clearable="false" @change="getTableData"/>
			<el-button v-if="isShowDigitalMonthlyReport" class="zs-btn-plain" @click="getTableData"> 查询 </el-button>
			<span class="zs-layout-flex-row zs-layout-justify-end zs-layout-grow">
				<el-button class="zs-btn-md" :class="{'zs-btn-primary': isShowDigitalMonthlyReport, 'zs-btn-info' : !isShowDigitalMonthlyReport}" @click="changeTab(true, false)" v-btnPermi="{permi: 'p_btn_jingyingbangong_shuziyuebao'}">数字月报</el-button>
				<el-button class="zs-btn-md" :class="{'zs-btn-primary': isShowDashboard, 'zs-btn-info' : !isShowDashboard}" @click="changeTab(false, true)">专项报表</el-button>
			</span>
		</div>
		<el-scrollbar class="db-content-height" v-if="isShow && isShowDashboard">
			<div class="db-content-cards">
				<BaseInfo :biProjectCode="biProjectCode" :projectCode="projectCode" :permi="tabPermi"></BaseInfo>
				<!-- 出租情况 -->
				<RentalSituation :title="''" :permi="'p_btn_901_bangongxiangmu_xiangqing_chuzu'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></RentalSituation>
				<!-- 租赁分析-场地 -->
				<LeaseAnalysis :permi="'p_btn_901_jingyingchanban_changdichuzu'" leaseType="place" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :updateDate="updateDate"></LeaseAnalysis>
				<!-- 租赁分析-库房 -->
				<LeaseAnalysis :permi="'p_btn_901_jingyingchanban_kufangchuzu'" leaseType="warehouse" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :updateDate="updateDate"></LeaseAnalysis>
				<!-- 租赁分析-广告 -->
				<LeaseAnalysis :permi="'p_btn_901_jingyingchanban_guanggaoweichuzu'" leaseType="ad" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :updateDate="updateDate"></LeaseAnalysis>
				<!--新签面积-->
				<NewSignature :permi="'p_btn_901_bangongxiangmu_xiangqing_xinqian'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></NewSignature>
				<!-- 工单监控 -->
				<WorkerOrder :permi="'p_btn_901_bangongxiangmu_xiangqing_gongdan'" :hideList="hideList" :projectCode="projectCode" :updateDate="updateDate"></WorkerOrder>
				<!--欠款分析-->
				<DebtInformation :permi="'p_btn_901_bangongxiangmu_xiangqing_qiankuan'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></DebtInformation>
				<!--保证金押金-->
				<DepositAndCashPledge :permi="'p_btn_901_bangongxiangmu_xiangqing_bzjyj'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></DepositAndCashPledge>
				<!-- 资本化改造 -->
				<CapitalizationTransformation :permi="'p_btn_901_bangongxiangmu_xiangqing_zbhgz'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></CapitalizationTransformation>
				<!-- 能耗分析 -->
				<EnergyCosts :permi="'p_btn_901_bangongxiangmu_xiangqing_nyf'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate" />
				<!-- 预算对标 -->
				<BudgetcAhievement :permi="'p_btn_901_bangongxiangmu_xiangqing_ysdb'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></BudgetcAhievement>
				<!--两算一控-->
				<TwoControl :permi="'p_btn_901_bangongxiangmu_xiangqing_twoandone_control'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></TwoControl>
				<!-- 费控分析 -->
				<CostControlAnalysis :permi="'p_btn_901_jingyingchanye_xiangqing_costanalysis'" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate" />
				<!-- 费控对标 -->
				<CostControlStandard :permi="'p_btn_901_bangongxiangmu_xiangqing_costcontrol_standards'" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate" />
				<!--整场测算  ps: 【广州中大珠江国际纺织城】项目暂时隐藏这个模块-->
				<NewSigning v-if="biProjectCode != 'GZ_CYY_FZCYQ'" :permi="'p_btn_901_jingyingbangong_xiangqing_xinqianqingkuang'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></NewSigning>
				<!--整场测算 新-->
				<WholeCalculation :permi="'p_btn_901_jingyingbangong_zhengchangcesuan'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></WholeCalculation>
				
				<!-- 两书对标 -->
				<LiangShu :permi="'p_btn_901_bangongxiangmu_xiangqing_lsdb'" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></LiangShu>
				<!-- 车场白名单 -->
				<CarParkWhiteList :permi="'p_btn_901_chanban_chechangbaimingdan'" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate"> </CarParkWhiteList>
				<!-- 车场异常抬杆 -->
				<AbnormalPoleLifting :permi="'p_btn_901_chanban_chechangyichangtaigan'" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate"> </AbnormalPoleLifting>

				<!-- 财务-开办费 -->
				<FinanceKaiBanFei :permi="'p_btn_901_chanban_xiangqing_startupexpenses'" :subjectType="4" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :yearmonth="yearmonth"> </FinanceKaiBanFei>
				<!-- 财务-利润率 -->
				<FinanceLiRunBiao :permi="'p_btn_901_chanban_xiangqing_commercialprofit'" :subjectType="3" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :yearmonth="yearmonth"> </FinanceLiRunBiao>
				<!-- 财务-投入产出表 -->
				<FinanceTouRuChanChu :permi="'p_btn_901_chanban_xiangqing_lnputoutput'" :subjectType="2" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :yearmonth="yearmonth"> </FinanceTouRuChanChu>
				<!-- 财务-资金来源占用表 -->
				<FinanceZiJinLaiYuanZhanYong :permi="'p_btn_901_chanban_xiangqing_sourceandfunds'" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :yearmonth="yearmonth"> </FinanceZiJinLaiYuanZhanYong>
			</div>
		</el-scrollbar>
		
		<DigitalMonthlyReport v-if="isShowDigitalMonthlyReport" :isFresh="isFresh" :biProjectCode="biProjectCode" :yearmonth="yearmonth" :tabPermi="tabPermi"></DigitalMonthlyReport>
	</div>
</template>
<script setup>
	import DigitalMonthlyReport from '@/views/Manage/Work/DigitalMonthlyReport/digitalMonthlyReport';
	import BaseInfo from '@/views/Manage/Business/components/baseInfo';
	import RentalSituation from '@/views/Manage/Business/components/rentalSituation';
	import NewSigning from '@/views/Manage/Business/components/newSigning';
	import WholeCalculation from '@/views/Manage/Business/components/wholeCalculation';
	import NewSignature from '@/views/Manage/Business/components/newSignature';
	import WorkerOrder from '@/views/Manage/Business/components/workerOrder';
	import DebtInformation from '@/views/Manage/Business/components/debtInformation';
	import DepositAndCashPledge from '@/views/Manage/Business/components/depositAndCashPledge';
	import CapitalizationTransformation from '@/views/Manage/Business/components/capitalizationTransformation';
	import BudgetcAhievement from '@/views/Manage/Business/components/budgetcAhievement';
	import LiangShu from '@/views/Manage/Business/components/liangShu';
	import TwoControl from '@/views/Manage/Business/components/twoControl';
	import EnergyCosts from '@/views/Manage/Business/components/energyCosts';
	import CostControlStandard from '@/views/Manage/Business/components/costControlStandard';
	import LeaseAnalysis from '@/views/Manage/Business/components/leaseAnalysis';
	import CarParkWhiteList from '@/views/Manage/Business/components/carParkWhiteList';
	import AbnormalPoleLifting from '@/views/Manage/Business/components/abnormalPoleLifting';
	import CostControlAnalysis from '@/views/Manage/Business/components/costControlAnalysis.vue'
	import FinanceKaiBanFei from '@/views/Manage/Business/components/financeKaiBanFei.vue'
	import FinanceLiRunBiao from '@/views/Manage/Business/components/financeLiRunBiao.vue'
	import FinanceTouRuChanChu from '@/views/Manage/Business/components/financeTouRuChanChu.vue'
	import FinanceZiJinLaiYuanZhanYong from '@/views/Manage/Business/components/financeZiJinLaiYuanZhanYong.vue'

	import dbPublicApi from '@/api/dbPublic';
	import { ref } from 'vue';
	import { useRoute } from 'vue-router';
	const route = useRoute().query;
	let biProjectCode = ref(route.biProjectCode);
	const projectCode = ref(route.projectCode);
	const updateDate = route.updateDate;
	const tabPermi = route.tabPermi;

	let isShowDigitalMonthlyReport = ref(false);
	let isShowDashboard = ref(true);
	const changeTab = (digital, dashboard) => {
		isShowDigitalMonthlyReport.value = digital
		isShowDashboard.value = dashboard
	}

	let isShow = ref(false);
	let hideList = ref([]);
	let projectList = ref([]);
	let biProjectName = ref('');
	const getHide = async () => {
		await dbPublicApi.queryMenuHidePcApi(biProjectCode.value).then(res => {
			if (res.data.code == 200) {
				hideList.value = res.data.data;
			}
		});
	};
	const getList = () => {
		dbPublicApi.queryProjectPcApi({ dataTime: updateDate, resourceKey: tabPermi }).then(res => {
			if (res.data.code == 200) {
				projectList.value = res.data.data;
                let target = projectList.value.find(item => {
					return item.biProjectCode == biProjectCode.value;
				});
				biProjectName.value = target ? target.projectName : '';
			}
		});
	};
	const changeProject = async () => {
		isShow.value = false;
		await getHide();
		const index = projectList.value.findIndex(item => {
			return item.biProjectCode == biProjectCode.value;
		});
		projectCode.value = projectList.value[index].projectCode;
		biProjectName.value = projectList.value[index].projectName;
		isShow.value = true;
	};

	// --------- 数字月报相关 start ---------
	const isFresh = ref(new Date().getTime().toString());
	const yearmonth = ref()	
	// 获取商业数据更新日期 年月 用于数字月报筛选
	const queryDataUpdateTime = async () => {
		await dbPublicApi.queryMonthsTimeApi().then(res=>{
			let resData = res.data
			if(resData.code == 200){
				yearmonth.value = resData.data
			}
		})
	}
	const getTableData = () => {
		isFresh.value = new Date().getTime().toString();
	}
	// --------- 数字月报相关 end ---------

	const init = async () => {
		await queryDataUpdateTime()
		isShow.value = false;
		await getHide();
		getList();
		isShow.value = true;
	};
	init();
</script>